home *** CD-ROM | disk | FTP | other *** search
- /*
- FILENAME
- ChooserSupport.c
-
- DESCRIPTION
- Contains code for PACK and LDEF resources used by the Chooser.
-
- COPYRIGHT
- Copyright © 1995 Apple Computer, Inc.
- All rights reserved.
-
- Modification history
- 05/03/95 - Dave Hersey - Version 1.0.1 to fix some minor bugs in
- CustomBufferingAndIO.c.
-
- 01/14/95 - Dave Hersey - Created from the shell of a hollowed-out
- ImageWriter driver.
-
- NOTE: Relevant goodies are listed in MPW's "Mark" menu.
-
- */
-
- #include "CommonDefines.h"
-
-
- /* -----------------------------------------------------------------------
-
- Device is the standard Chooser "Device" routine that all QuickDraw GX
- drivers require.
-
- ----------------------------------------------------------------------- */
-
- pascal OSErr Device(short message, short caller, StringPtr objName,
- StringPtr zoneName, ListHandle theList, long p2)
- {
-
- OSErr anErr = noErr;
- extern Str31 gDriverName;
- StringPtr pDriverName = &gDriverName;
- extern gxJob gJob;
- gxJob *pJob = &gJob;
-
- // start up GX.
-
- if (message == initializeMsg)
- {
- FCBPBRec pb;
-
- // determine the driver name
- pb.ioCompletion = nil;
- pb.ioNamePtr = pDriverName;
- pb.ioVRefNum = 0;
- pb.ioRefNum = CurResFile();
- pb.ioFCBIndx = 0;
- anErr = PBGetFCBInfo(&pb, false);
-
- *pJob = nil;
- if (anErr == noErr)
- {
- GXEnterGraphics();
- anErr = GXGetGraphicsError(nil);
- if (anErr == noErr)
- {
- anErr = GXInitPrinting();
- if (anErr != noErr)
- GXExitGraphics();
- }
- }
- }
-
- // Let the system handle the choosing for us.
-
- if (anErr == noErr)
- {
- if ((*pJob != nil) || (message == initializeMsg))
- {
- anErr = GXHandleChooserMessage(pJob, pDriverName, message, caller, objName, zoneName, theList, p2);
-
- // Tear down GX when done.
-
- if ((message == terminateMsg) && (p2 == terminateMsg))
- {
- GXExitPrinting();
- GXExitGraphics();
- }
- }
- }
-
- return anErr;
- }
-
-
- /* -----------------------------------------------------------------------
- LDEF is our driver's Chooser LDEF.
-
- This is an LDEF that simply plots an icon, and lets the user "Create."
-
- ----------------------------------------------------------------------- */
-
- pascal void LDEF(
- short message, // What operation to perform on list
- Boolean select, // Is this cell to be selected or not?
- Rect *theRect, // Rectangle of this cell, clipped to window
- Cell theCell, // Which cell this is
- short dataOffset, // Offset into data for this cell
- short dataLen, // Length of data for this cell
- ListHandle theList) // The list to act upon
- {
- Handle cicnHdl;
- Rect iconRect;
-
- #pragma unused(theCell, dataOffset, dataLen);
-
- switch (message)
- {
- case lInitMsg:
- {
- Cell aCell = {0, 1};
- (*theList)->userHandle = (Handle) GetCIcon(r_ChooserIcon);
-
- if ((*theList)->userHandle)
- {
- DetachResource((*theList)->userHandle);
- LSetCell("Print To Disk", 13, aCell, theList);
- LSetSelect(true, aCell,theList);
- }
- }
- break;
-
- case lCloseMsg:
- if ((*theList)->userHandle)
- {
- DisposeCIcon((CIconHandle) (*theList)->userHandle);
- (*theList)->userHandle = nil;
- }
- break;
-
- case lHiliteMsg:
- case lDrawMsg:
- cicnHdl = (*theList)->userHandle;
- if (cicnHdl == nil) break;
-
- // draw the cell as an icon
- // center the icon rect on the list with a top margin of 10 pixels
-
- iconRect.top = theRect->top + 10;
- iconRect.left = theRect->left + ((theRect->right - theRect->left) >> 1) - 16;
- iconRect.bottom = iconRect.top + 32;
- iconRect.right = iconRect.left + 32;
-
-
- // draw the icon
-
- if (cicnHdl != nil)
- PlotCIcon(&iconRect, (CIconHandle) cicnHdl);
-
- // Get the general area under the icon in which to draw the label
-
- iconRect.left = theRect->left + 2;
- iconRect.right = iconRect.left + (**theList).cellSize.h - 2;
- iconRect.top = iconRect.bottom + 2;
- iconRect.bottom = theRect->bottom;
-
- // use a nice small font for the label
-
- TextFont(applFont);
- TextSize(9);
-
- {
- short labelWidth;
- short rectWidth;
- short labelHeight;
- FontInfo theInfo;
- unsigned char theHilightMode;
-
- /* Get rid of any previous label, compute the height of the new label,
- compute where to draw the text, truncate the string to fit within the box,
- compute the new width of the string, center the string, and draw it.
- */
- EraseRect(&iconRect);
- iconRect.top += 2;
-
- GetFontInfo(&theInfo);
- labelHeight = theInfo.ascent +theInfo.leading;
-
- iconRect.bottom = iconRect.top + labelHeight;
- rectWidth = iconRect.right-iconRect.left;
-
- // Not very localizable... Use resources in the real world.
-
- TruncString(rectWidth, "\pPrint To Disk", smTruncEnd);
- labelWidth = StringWidth("\pPrint To Disk");
-
- iconRect.left += (rectWidth >> 1) - (labelWidth >> 1);
- MoveTo(iconRect.left, iconRect.bottom);
- DrawString("\pPrint To Disk");
-
- // If selecting the icon, highlight the text.
-
- if (select)
- {
- iconRect.right = iconRect.left + labelWidth;
- iconRect.bottom += theInfo.descent;
-
- InsetRect(&iconRect, -1, -1);
-
- theHilightMode = LMGetHiliteMode();
- BitClr(&theHilightMode, pHiliteBit);
- LMSetHiliteMode(theHilightMode);
- InvertRect(&iconRect);
- }
-
- TextFont(applFont);
- TextSize(0);
- }
- break;
- }
- }
-
-